﻿Imports System.Data
Imports System.Data.OleDb
Imports DTO
Public Class LichKhoiHanhDao
    Dim provider As New DataProvider

    Public Function LayDanhSachLichLap() As DataTable
        Dim sql As String = "SELECT * FROM LichLap"
        Return provider.ThucThiCauTruyVan(sql)
    End Function

    Public Function TimLichLap(ByVal lichLap As LichKhoiHanhDto) As DataTable
        Dim sql As String = "SELECT * FROM LichLap WHERE 1"
        If lichLap.MaLap <> 0 Then
            sql += " and MaLap =" & lichLap.MaLap & " "
        End If
        If lichLap.ThuLap <> "" Then
            sql += " and ThuLap = '" & lichLap.ThuLap & "' "
        End If

        Return provider.ThucThiCauTruyVan(sql)
    End Function

    Public Function TimTuyenTheoMaLap(ByVal maLap As Integer) As DataTable
        Dim sql As String = "SELECT * FROM LichLap WHERE maLap = " & maLap

        Dim dtLichLap As DataTable
        dtLichLap = provider.ThucThiCauTruyVan(sql)

        Return dtLichLap
    End Function


    Public Function ThemLichLap(ByVal lichLap As LichKhoiHanhDto) As Integer
        Dim sql As String = "INSERT INTO LichLap(ThuLap) VALUES (?)"

        Dim dsParameter As New List(Of OleDbParameter)
        dsParameter.Add(New OleDbParameter("@ThuLap", lichLap.ThuLap))

        Return provider.ThucThiTruyVanThuong(sql, dsParameter)
    End Function

    Public Function CapNhatLichLap(ByVal lichLap As LichKhoiHanhDto) As Integer
        Dim sql As String = "UPDATE LichLap SET ThuLap = ? WHERE MaLap = ?"

        Dim dsParameter As New List(Of OleDbParameter)
        dsParameter.Add(New OleDbParameter("@ThuLap", lichLap.ThuLap))

        Return provider.ThucThiTruyVanThuong(sql, dsParameter)
    End Function

    Public Function XoaLichLap(ByVal maLap As Long) As Integer
        Dim sql As String = "DELETE FROM LichLap WHERE MaLap = ?"

        Dim dsParameter As New List(Of OleDbParameter)
        dsParameter.Add(New OleDbParameter("@MaLap", maLap))
        Return provider.ThucThiTruyVanThuong(sql, dsParameter)

    End Function

    Public Function CapNhatXuongCSDL(ByVal tenBang As String, ByVal dt As DataTable) As Integer
        Return provider.CapNhatXuongCSDL(tenBang, dt)
    End Function
End Class
